package com.tongcao.cn.validator.cons;

import com.google.common.collect.Maps;

import java.lang.reflect.Field;
import java.util.Map;

/**
 * @Author:tongcao
 * @Date:2019/4/26 15:44
 * Description:
 */
public class ErrorCodeConstans {
    public static final String PHONE = "PHONE_ERROR_CODE";

    public static final String MOBILE = "MOBILE_ERROR_CODE";

    public static final String EMAIL = "EMAIL_ERROR_CODE";

    public static final String DOMAIN = "DOMAIN_ERROR_CODE";

    public static final String URL = "URL_ERROR_CODE";

    public static final String DATE = "DATE_ERROR_CODE";

    public static final String MAX = "MAX_ERROR_CODE";

    public static final String MAX_LENGTH = "MAX_LENGTH_ERROR_CODE";

    public static final String MIX = "MIX_ERROR_CODE";

    public static final String MIN_LENGTH = "MIX_LENGTH_ERROR_CODE";

    public static final String NOT_BLANK = "NOT_BLANK_ERROR_CODE";

    public static final String NOT_EMPTY = "NOT_EMPTY_ERROR_CODE";

    public static final String NOT_NULL = "NOT_NULL_ERROR_CODE";

    public static final String RANGE = "RANGE_ERROR_CODE";

    public static final String SIZE = "SIZE_ERROR_CODE";

    public static final String ENUM = "ENUM_ERROR_CODE";


    public static void main(String[] args) {

        Map<String, String> errorCodeMap = Maps.newHashMap();
        Field[] fields = ErrorCodeConstans.class.getFields();
        try {
            for (Field field : fields) {
                field.setAccessible(true);
                errorCodeMap.put(field.getName(), String.valueOf(field.get(field.getName())));
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        Map<String, String> messageMap = Maps.newHashMap();
        Field[] fields1 = MessageConstans.class.getFields();
        try {
            for (Field field : fields1) {
                field.setAccessible(true);
                messageMap.put(field.getName(), String.valueOf(field.get(field.getName())));
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        StringBuilder sb = new StringBuilder();
        int i = 0;
        for (Map.Entry entry : errorCodeMap.entrySet()) {
            if (i < errorCodeMap.size()-1) {
                sb.append(entry.getKey()).append("(\"").append(entry.getValue()).append("\",\"").append(messageMap.get(entry.getKey())).append("\"),\n");
            } else {
                sb.append(entry.getKey()).append("(\"").append(entry.getValue()).append("\",\"").append(messageMap.get(entry.getKey())).append("\");\n");
            }
            i++;
        }

        System.out.println(sb.toString());
    }
}